﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using ZJ.Finance.BusinessRule;
using ZJ.Finance.DataModel;

namespace Finance.Controllers
{
    public class HtmlController : Controller
    {
        //
        // GET: /Html/
        public String Index()
        {
            User user = DataProvider.GetCurrentUser();
           // var user = new User {LoginEmail = "wubiyu_111@163.com"};
            var datas = new Dictionary<string, object>();
            try
            {

                //List<BillOperation> operations = DataProvider.Instance.GetBillOperations();
                List<Account> accounts = DataProvider.Instance.GetAccounts(string.Empty, string.Format("LoginEmail='{0}'", user.LoginEmail));
                List<BillCategory> categorys = DataProvider.Instance.GetBillCategories(string.Empty, string.Format("LoginEmail='{0}'", user.LoginEmail));
                List<Project> projects = DataProvider.Instance.GetProjects(string.Empty, string.Format("Members like '%|{0}|%' OR Members like '%|System|%'", user.LoginEmail));
                datas.Add("Error",false);
                //datas.Add("Operations", operations);
                datas.Add("Accounts", accounts);
                datas.Add("Categorys",categorys);
                datas.Add("Projects", projects);
              
            }
            catch (Exception ex)
            {
                datas.Add("Error",true);
                datas.Add("ErrorMsg", ex.ToString());
            }

            return DataProvider.GetJosnp(JsonConvert.SerializeObject(datas, new JavaScriptDateTimeConverter()));
        }

        

    }
}
